#include "Vector.h"
#include <bits/stdc++.h>
using namespace std;
#define N 100000000;

double test(const int & n)
{
    clock_t t0=clock();
    Vector<int> a;
    for(int i=0;i<n;++i)
        a.push_back(0);
    return (double)(clock()-t0)/CLOCKS_PER_SEC;
}

void randintVec(Vector<int> &A)
{
    for(int i=0;i<A.size();++i)
        A[i]=rand()&63;
}

void randdoubleVec(Vector<double> &A)
{
    for(int i=0;i<A.size();++i)
        A[i]=(rand()&32767)/255;
}

int main(){
    srand(time(0)+19260817);
    cout<<"Let's start our test!"<<endl;
    //test 1
    cout<<"Now we create a zero vector A and empty vector B"<<endl;
    Vector<int> A(5),B;
    for(int i=0;i<A.size();i++) A[i]=0;
    cout<<"A="<<A<<endl;
    cout<<"Now we give random value to A"<<endl;
    randintVec(A);
    cout<<"A="<<A<<endl;
    cout<<"Now we check B"<<endl;
    cout<<"B="<<B<<endl;
    cout<<"Now we copy A to B"<<endl;
    B=A;
    cout<<"B="<<B<<endl;
    cout<<"Now we create another copy of A:C"<<endl;
    Vector<int> C(A);
    cout<<"C="<<C<<endl;
    cout<<endl;
    //test 2
    cout<<"Now we create a const vector D,create a empty vector E,also copy D to E,by the way check function empty"<<endl;
    const Vector<double> D(5);
    cout<<"D="<<D<<endl;
    Vector<double> E;
    cout<<"E="<<E<<endl;
    cout<<"E.empty()="<<E.empty()<<endl;
    E=D;
    cout<<"E="<<E<<endl;
    cout<<"E.empty()="<<E.empty()<<endl;
    cout<<endl;
    //test 3
    cout<<"Now we create a 2-vector F and check its size and capacity"<<endl;
    Vector<int> F(Vector<int>(2));
    cout<<"F="<<F<<endl;
    cout<<"the capacity 0f F="<<F.capacity()<<endl;
    cout<<"then we resize F to 259, give it random value, and check it"<<endl;
    F.resize(259);
    randintVec(F);
    cout<<"F="<<F<<endl;
    cout<<"the capacity 0f F is "<<F.capacity()<<endl;
    cout<<"the size 0f F is "<<F.size()<<endl;
    cout<<"F[258]="<<F[258]<<endl;
    cout<<"the end of F is "<<F.back()<<endl;
    cout<<endl;
    //test 4
    cout<<"Now we check the capacity of B"<<endl;
    cout<<"the capacity 0f B is "<<B.capacity()<<endl;
    cout<<"then we reserve B to 262, and check it"<<endl;
    B.reserve(262);
    cout<<"B="<<B<<endl;
    cout<<"the capacity 0f B ia "<<B.capacity()<<endl;
    cout<<endl;
    //test 5
    cout<<"Now we use the iterator to check C"<<endl;
    Vector<int>::iterator p=C.begin();
    cout<<"C="<<C<<endl;
    cout<<"the begin of C is "<<*p<<endl;
    p=C.end();
    cout<<"the end of C is "<<*(--p)<<endl;
    cout<<"Now we push 1 and 2 to the end of C, and check it"<<endl;
    C.push_back(1);
    C.push_back(1+1);
    p=C.end();
    cout<<"the end of C is "<<*(--p)<<endl;
    cout<<"Now we push a random value and the number follow it to the end of C, and check it"<<endl;
    int a=rand()&63;
    C.push_back(a);
    C.push_back(a+1);
    p=C.end();
    cout<<"the end of C is "<<*(--p)<<endl;
    cout<<"C="<<C<<endl;
    C.pop_back();
    p=C.end();
    cout<<"Now we pop the ladt value of C, and check it"<<endl;
    cout<<"the end of C is "<<*(--p)<<endl;
    cout<<"C="<<C<<endl;
    cout<<endl;
    //test*
    int n=0;
    double t=0;
    for(int i=0;i<100;i++){
        n=((rand()<<15)|rand())%N;
        t+=test(n);
    }
    cout<<"test*:The total time is"<<setprecision(4)<<t<<endl;
    cout<<"Our test is over, thank you!"<<endl;    
    return 0;
}